# -*- coding: utf-8 -*-
import scrapy
from mySpider.items import MeiTuItem

class MeituSpider(scrapy.Spider):
    name = 'meitu'
    allowed_domains = ['mntup.com']
    start_urls = ['https://www.mntup.com/TouTiao/moxiaoxi_ac27649a.html']

    def parse(self, response):
        context = response.xpath('/html/head/title/text()')
        # 提取网站标题
        title = context.extract_first()
        print(title)
        urls = response.xpath('//img[@onload="size(this)"]/@src').extract()
        item = MeiTuItem()
        img_paths = []
        for url in urls:
            img_url = 'https://www.mntup.com' + url
            print(img_url)
            item['name'] = title
            img_paths.append(img_url)
        item['url'] = img_paths
        yield item